package drive.Controller;

import drive.Model.ChatMessage;
import drive.Service.ServiceInterface.ChatMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/chatmessage")
public class ChatMessageController {
    @Autowired
    private ChatMessageService chatMessageService;

    // 查询所有聊天消息
    @GetMapping()
    public String selectAllChatMessages() {
        return chatMessageService.findAll();
    }

    // 根据messageID查询聊天消息
    @GetMapping("/{messageID}")
    public String selectChatMessageByMessageID(@PathVariable("messageID") int messageID) {
        return chatMessageService.findByMessageID(messageID);
    }

    // 根据chatSessionID查询聊天消息
    @GetMapping("/session/{chatSessionID}")
    public String selectChatMessagesByChatSessionID(@PathVariable("chatSessionID") int chatSessionID) {
        return chatMessageService.findByChatSessionID(chatSessionID);
    }

    // 根据senderID查询聊天消息
    @GetMapping("/sender/{senderID}")
    public String selectChatMessagesBySenderID(@PathVariable("senderID") int senderID) {
        return chatMessageService.findBySenderID(senderID);
    }

    // 新增聊天消息
    @PostMapping()
    public String addChatMessage(@RequestBody ChatMessage chatMessage) {
        return chatMessageService.add(chatMessage);
    }

    // 更新聊天消息
    @PutMapping()
    public String updateChatMessage(@RequestBody ChatMessage chatMessage) {
        return chatMessageService.update(chatMessage);
    }

    // 删除聊天消息
    @DeleteMapping("/{messageID}")
    public String deleteChatMessage(@PathVariable("messageID") int messageID) {
        return chatMessageService.delete(messageID);
    }
}